bunoj 1006

WA了好多次,原来当个数大于1的时候是operations,忘记加s,坑啊




Primary Arithmetic

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name:  Main
Prev  Submit  Status  Statistics  Discuss  Next
Font Size:  +   -
Type:  NoneGraph Theory     2-SAT    Articulation/Bridge/Biconnected Component     Cycles/Topological Sorting/Strongly Connected Component     Shortest Path         Bellman Ford        Dijkstra/Floyd Warshall     Euler Trail/Circuit     Heavy-Light Decomposition     Minimum Spanning Tree     Stable Marriage Problem     Trees     Directed Minimum Spanning Tree     Flow/Matching        Graph Matching             Bipartite Matching             Hopcroft–Karp Bipartite Matching             Weighted Bipartite Matching/Hungarian Algorithm         Flow             Max Flow/Min Cut             Min Cost Max Flow DFS-like    Backtracking with Pruning/Branch and Bound     Basic Recursion     IDA* Search    Parsing/Grammar     Breadth First Search/Depth First Search     Advanced Search Techniques         Binary Search/Bisection         Ternary Search Geometry     Basic Geometry    Computational Geometry     Convex Hull     Pick's TheoremGame Theory     Green Hackenbush/Colon Principle/Fusion Principle     Nim     Sprague-Grundy Number Matrix    Gaussian Elimination     Matrix Exponentiation Data Structures     Basic Data Structures     Binary Indexed Tree     Binary Search Tree     Hashing    Orthogonal Range Search     Range Minimum Query/Lowest Common Ancestor     Segment Tree/Interval Tree     Trie Tree     Sorting    Disjoint Set String     Aho Corasick    Knuth-Morris-Pratt     Suffix Array/Suffix Tree Math     Basic Math    Big Integer Arithmetic     Number Theory         Chinese Remainder Theorem         Extended Euclid         Inclusion/Exclusion         Modular Arithmetic     Combinatorics        Group Theory/Burnside's lemma         Counting     Probability/Expected Value Others    Tricky     Hardest    Unusual     Brute Force     Implementation    Constructive Algorithms     Two Pointer     Bitmask    Beginner     Discrete Logarithm/Shank's Baby-step Giant-step Algorithm     Greedy     Divide and Conquer Dynamic Programming     Tag it!
当你在小学学习算数的时候,老师会教你把两个数由右至左按位加起来。很多时候,加法过程中会出现进位。对于一部分孩子,理解这个“进位”在当时是很困难的事情。现在你的工作就是编写一个程序来判断两个数相加的过程中会产生多少次进位,用以确定这两个数相加的“难度”。

Input

每一行有两个无符号整数(最大不超过1000000000),当输入0 0的时候,程序结束。

Output

对于每一行的输入两个整数,你需要判断会产生有多少个进位,每一个输出占一行。

Sample Input

123 456
555 555
123 594
0 0

Sample Output

No carry operation.
3 carry operations.
1 carry operation.

#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    int a,b,cnt;
    while(cin>>a>>b&&(a||b))
    {
       int s=0;
       cnt=0;
        while(a&&b)
        {
            int t1=a%10;
            a/=10;
            int t2=b%10;
            b/=10;
            if(s+t1+t2>=10)
                s=1,cnt++;
            else
                s=0;
        }
        while(a)
        {
            if(a%10+s>=10)
                cnt++,s=1;
                else
                    s=0;
                a/=10;
        }
        while(b)
        {
            if(b%10+s>=10)
                cnt++,s=1;
                else
                    s=0;
                b/=10;
        }
        if(cnt==1)
            cout<             else if(cnt>1)
                cout<         else
            cout<<"No carry operation."<<"\n";
    }
    return 0;
}

你可能感兴趣的:(bunoj 1006)